//
//  XHOftenGoPlaceViewController.m
//  testApp
//
//  Created by ColdMountain on 2017/4/5.
//  Copyright © 2017年 ColdMountain. All rights reserved.
//

#import "XHOftenGoPlaceViewController.h"

#import "XHOftenPlaceCell.h"
#import "XHPlaceCell.h"
#define SCREEN_HEIGHT                   ([UIScreen mainScreen].bounds.size.height)
#define SCREEN_WIDTH                    ([UIScreen mainScreen].bounds.size.width)
@interface XHOftenGoPlaceViewController ()
@property (weak, nonatomic) IBOutlet UITableView *ui_tableView;
@property (weak, nonatomic) IBOutlet UIButton *ui_selectCity;
@property (weak, nonatomic) IBOutlet UITextField *ui_searchText;
@property (weak, nonatomic) IBOutlet UIButton *ui_cancelButton;
@property (weak, nonatomic) IBOutlet UIView *ui_bgView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *la_bgViewTopBottm;
@property (strong, nonatomic) NSArray * m_array;

@end

@implementation XHOftenGoPlaceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.m_array = [NSArray new];
    self.m_array = @[@{@"title":@"赛格国际购物中心",
                      @"detail":@"陕西省西安市雁塔区长安中路123号"},
                     @{@"title":@"万达购物中心",
                       @"detail":@"陕西省西安市碑林区雁塔北路"},
                     @{@"title":@"城西客运站",
                       @"detail":@"陕西省西安市莲湖区枣园东路92号"},
                     @{@"title":@"回民街",
                       @"detail":@"陕西省西安市莲湖区西大街1号鼓楼广场"},
                     @{@"title":@"立丰国际购物中心",
                       @"detail":@"陕西省西安市碑林区金花南路"},
                   ];
    [PublicMethod setExtraCellLineHidden:self.ui_tableView];
    [self.ui_tableView registerNib:[UINib nibWithNibName:@"XHOftenPlaceCell" bundle:nil] forCellReuseIdentifier:XHOftenPlaceCellIdentifier];
    [self.ui_tableView registerNib:[UINib nibWithNibName:@"XHPlaceCell" bundle:nil] forCellReuseIdentifier:XHPlaceCellIdentifier];
    self.ui_tableView.layer.masksToBounds=YES;
    self.ui_tableView.layer.cornerRadius=5;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)cancelAction:(id)sender
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"showNavView" object:nil];
    [self dismissViewControllerAnimated:YES completion:^{

    }];
}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.m_array.count+1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = nil;
    if (indexPath.row==0)
    {
        cell = [self oftenPlaceCell];
    }
    else
    {
        cell = [self placeCell:indexPath];
    }
    return cell;
}

- (XHOftenPlaceCell *)oftenPlaceCell
{
    XHOftenPlaceCell * cell = [self.ui_tableView dequeueReusableCellWithIdentifier:XHOftenPlaceCellIdentifier];
    
    return cell;
}

- (XHPlaceCell *)placeCell:(NSIndexPath*)indexPath
{
    XHPlaceCell * cell = [self.ui_tableView dequeueReusableCellWithIdentifier:XHPlaceCellIdentifier];
    NSDictionary * dic = self.m_array[indexPath.row-1];
    cell.ui_placeLabel.text = [NSString stringWithFormat:@"%@",dic[@"title"]];
    cell.ui_detailAddressLabel.text = [NSString stringWithFormat:@"%@",dic[@"detail"]];
    return cell;
}

#pragma - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height=0;
    if (indexPath.row==0)
    {
        height = 65;
    }
    else
    {
        height = 60;
    }
    return height;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
